package com.patrick.util;
/**
 * DerbyJndiBind.java
 * Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
 */
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import org.apache.derby.jdbc.*;
public class DerbyJndiBind {
  public static void main(String [] args) {
    Connection con = null;
    try {

// Starting the Directory service
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, 
        "com.sun.jndi.fscontext.RefFSContextFactory");
      env.put(Context.PROVIDER_URL, "file:/local/fscontext");
      Context ctx = new InitialContext(env);

// Creating a DataSource object
      ClientDataSource ds 
        = new org.apache.derby.jdbc.ClientDataSource();
      ds.setServerName("localhost");
      ds.setDatabaseName("TestDB");

// Storing the DataSource object
      ctx.bind("DerbyTestDB", ds);
      System.out.println("ClientDataSource object stored ok.");

    } catch (Exception e) {
      System.err.println("Exception: "+e.getMessage());
    }
  }
}